package com.candicom.race.rings;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public abstract class AbstractRing {

    private final BufferedImage mask;
    private final Image image;
    private final Rectangle rect;

    AbstractRing(String _maskName, String _imageName) throws Exception {
        mask = ImageIO.read(Object.class.getResource("/com/candicom/race/rings/images/" + _maskName));
        image = ImageIO.read(Object.class.getResource("/com/candicom/race/rings/images/" + _imageName));
        rect = new Rectangle(mask.getWidth(), mask.getHeight());
    }

    public abstract Point getStartPoint(int _playerNo);

    public abstract int getStartAngle();

    public abstract int getCrashForce();

    public abstract int getFriction();

    public final Dimension getDimension() {
        return rect.getSize();
    }

    public final boolean isAvailable(Point _loc) {
        if (rect.contains(_loc) == false) {
            return false;
        } else {
            return (mask.getRGB(_loc.x, _loc.y) == -1);
        }
    }

    public final Image getImage() {
        return image;
    }
}
